﻿/*
Copyright (c) pietro partescano

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished 
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 
IN THE SOFTWARE. 
*/

using System;
using System.Text;
using System.Collections.Generic;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestProject
{
    /// <summary>
    /// Summary description for UnitTest
    /// </summary>
    [TestClass]
    public class UnitTest
    {
        public UnitTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion


        [TestMethod]
        public void TestMethod4()
        {

            var c = System.Text.RegularExpressions.Regex.Match(@"c:\tmp\wordpress-3.8.3.zip", "(zip)").Success;


            int i = 0;

        }

        [TestMethod]
        public void TestMethod3()
        {
            ///TODO:: INSERIRE FILTRO!


        }


        [TestMethod]
        public void TestMethod2()
        {
            ///TODO:: INSERIRE FILTRO!
            

            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@"c:\tmp\Test_Images\");
            System.IO.FileInfo[] fi_s = di.GetFiles("*.*", System.IO.SearchOption.AllDirectories);

            ICSharpCode.SharpZipLib.Zip.ZipOutputStream fz = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(System.IO.File.Create("c:\\tmp\\out.zip"));
            //fz.Password = "aaa";
            //fz.SetLevel(9);
            fz.SetComment("TEST 12345");
            

            
            foreach (System.IO.FileInfo fi in fi_s)
            {
                byte[] f = System.IO.File.ReadAllBytes(fi.FullName);
                string file_name = "";
                ICSharpCode.SharpZipLib.Zip.ZipEntry ze = null;

                //Relative Path
                ICSharpCode.SharpZipLib.Zip.ZipNameTransform zn = new ICSharpCode.SharpZipLib.Zip.ZipNameTransform(@"c:\tmp\Test_Images\");
                file_name = zn.TransformFile(fi.FullName);
                ze = new ICSharpCode.SharpZipLib.Zip.ZipEntry(file_name);


                //Absolute Path
                file_name = ICSharpCode.SharpZipLib.Zip.ZipEntry.CleanName(fi.FullName);
                ze = new ICSharpCode.SharpZipLib.Zip.ZipEntry(file_name);


                //No Path
                file_name = fi.Name;
                ze = new ICSharpCode.SharpZipLib.Zip.ZipEntry(file_name);                
                
                fz.PutNextEntry(ze);
                fz.Write(f, 0, f.Length);
                fz.CloseEntry();
            }


            fz.Flush();
            fz.Close();
        }


        [TestMethod]
        public void TestMethodTAR_GZ()
        {
            using (ICSharpCode.SharpZipLib.GZip.GZipInputStream gzip = new ICSharpCode.SharpZipLib.GZip.GZipInputStream(System.IO.File.OpenRead(@"c:\tmp\out.tar.gz")))
            {
                int n = 0;
                int i = 0;
                while (i >= 0)
                {
                    i = gzip.ReadByte();
                    n++;
                }

                //gzip.Flush();
                //gzip.Close();
            }
           

        }



        [TestMethod]
        public void TestMethod1()
        {
            ICSharpCode.SharpZipLib.Zip.FastZip z = new ICSharpCode.SharpZipLib.Zip.FastZip();
            //z.CreateZip("c:\\tmp\\out.zip", @"c:\_VM_\_VM_Dev_\", false, "Windows XP Professional-000002.vmdk");

            ICSharpCode.SharpZipLib.Zip.ZipFile zfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(@"c:\tmp\a1.zip");
            zfile.BeginUpdate();
            zfile.SetComment(null);
            zfile.CommitUpdate();

            zfile.TestArchive(true);
        }
    }
}
